package com.gw.smscheck.controller.business.tools;

import com.github.pagehelper.PageInfo;
import com.gw.smscheck.entity.business.tools.Tools;
import com.gw.smscheck.service.business.tools.ToolsService;
import com.gw.smscheck.util.ResultConversion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 舆情检索接口
 *
 * @author ASUS
 */
@Controller
@RequestMapping("/toolsController")
@Api(description = "【小工具接口】")
public class ToolsController {


    @Autowired
    private ToolsService toolsService;


    /**
     * 跳转到查询页面
     *
     * @return
     */
    @RequestMapping("/goPage")
    @ApiIgnore
    public String goPage() {
        return "views/business.tools/tools";
    }
    /**
     * 手机号查询省份证号
     * @return
     */
    @ApiOperation(value="手机号查询省份证号", notes="手机号查询省份证号")
    @RequestMapping(value = "/findByPhone", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public String findByPhone(Tools tools){

        int codeParam = tools.getCode();
        PageInfo<Tools> pageInfo;
        if (codeParam != 1&& codeParam != 2 && codeParam != 3){
            return "请选择检索方式!";
        }else{
            if (codeParam == 1){
                pageInfo = toolsService.findByPhone(tools);
            }
            else if(codeParam == 2){
                pageInfo = toolsService.findByUserId(tools);
            }else{
                pageInfo = toolsService.findByImei(tools);
            }
            return ResultConversion.ToEasyUIDataGrid(pageInfo).toJSONString();

        }

    }

}
